using Microsoft.Xna.Framework;

namespace WODPL.GameComponents
{
    public class GameComponentContainer : DrawableGameComponent
    {
        private readonly GameComponentCollection components = new GameComponentCollection();

        public GameComponentContainer(Game game) : base(game)
        {
        }

        public GameComponentCollection Components
        {
            get { return components; }
        }

        public override void Initialize()
        {
            base.Initialize();
            foreach (var component in components)
            {
                component.Initialize();
            }
        }

        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
            foreach (var component in components)
            {
                var drawable = component as IDrawable;
                if (drawable != null)
                {
                    drawable.Draw(gameTime);
                }
            }
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            foreach (var component in components)
            {
                var updateable = component as IUpdateable;
                if (updateable != null)
                {
                    updateable.Update(gameTime);
                }
            }
        }
    }
}